*********************************************************
*********************************************************  
*** G24 --- JEBO Revision Package ***********************
*** Code for stats analyses *****************************
*** Public (anonymized) *********************************
*********************************************************



*******************************
* Note: the replication package provides the Stata SE 18 analysis code in this .do file and the data in the .dta file. I assume both are in the same directory. The unused city variable was removed for potential privacy reasons. You may need to download a package for the boottest command.
*******************************



clear all
set more off

** Load dataset
use ".../G24_OnYourOwnSideoftheFence.dta"



******************************* 
******* Data Preparation ****** 
******** Redistribution ******* 
******************************* 
		   
** Diverse labels
label var session "Session number in the experiment (24 separate sessions in total)"
label var subject "Session ID of participant (always 1--10)"
label var ethnicity "Ethnicity"
label var wage "Wage in the experiment: low (l) or high (h)"
label var proposal "Redistribution rate proposed (-10% to 115%)"
label var pair "Session ID of paired participant"
label var pairgender "Gender of paired participant"
label var pairethnicity "Ethnicity of paired participant"
label var pairwage "Wage of paired participant: low or high"
label var nationality "Nationality"
label var state "State"
label var age "Age"
label var major "Study major"
label var pol "Political leaning"
label var income "Family income"
label var redistr "Income redistribution support"
label var ehigh "Does luck or effort causes high income?"
label var elow "Does luck or effort causes low income?"
label var experience "Number of previous studies in which participant took part"
label var selection "Round with endogenously selected interactions (few obtain their first choice(s))"
label var firstsel "Obtained first choice of paired participant in endogenous interaction"
label var rank1 "Session ID of participant selected in rank 1 for interactions"
label var rank2 "Session ID of participant selected in rank 2 for interactions"
label var rank3 "Session ID of participant selected in rank 3 for interactions"
label var rank4 "Session ID of participant selected in rank 4 for interactions"
label var rank5 "Session ID of participant selected in rank 5 for interactions"
label var rank6 "Session ID of participant selected in rank 6 for interactions"
label var rank7 "Session ID of participant selected in rank 7 for interactions"
label var rank8 "Session ID of participant selected in rank 8 for interactions"
label var rank9 "Session ID of participant selected in rank 9 for interactions"
label var erank1 "Ethnicity of participant selected in rank 1 for interactions"
label var erank2 "Ethnicity of participant selected in rank 2 for interactions"
label var erank3 "Ethnicity of participant selected in rank 3 for interactions"
label var erank4 "Ethnicity of participant selected in rank 4 for interactions"
label var erank5 "Ethnicity of participant selected in rank 5 for interactions"
label var erank6 "Ethnicity of participant selected in rank 6 for interactions"
label var erank7 "Ethnicity of participant selected in rank 7 for interactions"
label var erank8 "Ethnicity of participant selected in rank 8 for interactions"
label var erank9 "Ethnicity of participant selected in rank 9 for interactions"
label var srank1 "Gender of participant selected in rank 1 for interactions"
label var srank2 "Gender of participant selected in rank 2 for interactions"
label var srank3 "Gender of participant selected in rank 3 for interactions"
label var srank4 "Gender of participant selected in rank 4 for interactions"
label var srank5 "Gender of participant selected in rank 5 for interactions"
label var srank6 "Gender of participant selected in rank 6 for interactions"
label var srank7 "Gender of participant selected in rank 7 for interactions"
label var srank8 "Gender of participant selected in rank 8 for interactions"
label var srank9 "Gender of participant selected in rank 9 for interactions"

** Remove subjects who participated twice (drop second participation) due to an
* error in the invitation system
rename ID id
label var id "ID number of participant in experiment"
drop if id==214
drop if id==170
drop if id==180
drop if id==233
drop if id==217
drop if id==178
drop if id==162
drop if id==211
drop if id==182
drop if id==176
drop if id==195
drop if id==230
drop if id==172
drop if id==137
drop if id==208
drop if id==213
drop if id==240

** Correct number of friends for one session in which software didn't accept
* 0 friend as possible answer
replace nb_friends_in_session=0 if nb_friends_in_session==11
replace nb_friends_in_session=1 if nb_friends_in_session==10
label var nb_friends_in_session "Number of (self-reported) friends in the experimental session"

** Code variables
* Re-code variable for rounds (takes 0 for first round, 1 for second round,
* and 2 for third round)
replace round=0 if round==1
replace round=1 if round==2
replace round=2 if round==3
label var round "Round number for three rounds: 0, 1, 2"

* Create own wage variable
gen high_wage=0
replace high_wage=1 if wage=="h"
label var high_wage "Indicator for participant with high wage"

* Create wage variable for the participant with whom one is paired
gen pair_high_wage=0
replace pair_high_wage=1 if pairwage=="h"
label var pair_high_wage "Indicator for being paired with high-wage participant"

* Create session dummies
gen g1=0
replace g1=1 if session==1
gen g2=0
replace g2=1 if session==2
gen g3=0
replace g3=1 if session==3
gen g4=0
replace g4=1 if session==4
gen g5=0
replace g5=1 if session==5
gen g6=0
replace g6=1 if session==6
gen g7=0
replace g7=1 if session==7
gen g8=0
replace g8=1 if session==8
gen g9=0
replace g9=1 if session==9
gen g10=0
replace g10=1 if session==10
gen g11=0
replace g11=1 if session==11
gen g12=0
replace g12=1 if session==12
gen g13=0
replace g13=1 if session==13
gen g14=0
replace g14=1 if session==14
gen g15=0
replace g15=1 if session==15
gen g16=0
replace g16=1 if session==16
gen g17=0
replace g17=1 if session==17
gen g18=0
replace g18=1 if session==18
gen g19=0
replace g19=1 if session==19
gen g20=0
replace g20=1 if session==20
gen g21=0
replace g21=1 if session==21
gen g22=0
replace g22=1 if session==22
gen g23=0
replace g23=1 if session==23
gen g24=0
replace g24=1 if session==24

label var g1 "Indicator for session 1"
label var g2 "Indicator for session 2"
label var g3 "Indicator for session 3"
label var g4 "Indicator for session 4"
label var g5 "Indicator for session 5"
label var g6 "Indicator for session 6"
label var g7 "Indicator for session 7"
label var g8 "Indicator for session 8"
label var g9 "Indicator for session 9"
label var g10 "Indicator for session 10"
label var g11 "Indicator for session 11"
label var g12 "Indicator for session 12"
label var g13 "Indicator for session 13"
label var g14 "Indicator for session 14"
label var g15 "Indicator for session 15"
label var g16 "Indicator for session 16"
label var g17 "Indicator for session 17"
label var g18 "Indicator for session 18"
label var g19 "Indicator for session 19"
label var g20 "Indicator for session 20"
label var g21 "Indicator for session 21"
label var g22 "Indicator for session 22"
label var g23 "Indicator for session 23"
label var g24 "Indicator for session 24"

* Create variables for one's gender and the gender of the participant with whom
* one is paired (correct mistake "man;" by "man" for some observations)
label var gender "Indicator for man or woman"
replace gender="man" if gender=="man;"
gen man=0
replace man=1 if gender=="man"
label var man "Indicator for man (vs. woman)"
gen pair_man=0
replace pair_man=1 if pairgender=="man"
label var pair_man "Indicator for being paired with a man (vs. woman)"

* Create ethnicity variables
gen white=0
replace white=1 if ethnicity=="White"
replace white=1 if ethnicity=="white"
replace white=1 if ethnicity=="White "
replace white=1 if ethnicity=="Albanian"
replace white=1 if ethnicity=="Israeli-White"
replace white=1 if ethnicity=="Caucasian"
replace white=1 if ethnicity=="Non-hispanic"
replace white=1 if ethnicity=="Caucasian/White"
replace white=1 if ethnicity=="causasian"
replace white=1 if ethnicity=="Caucasion"
label var white "Indicator for white participant"

gen hisp=0
replace hisp=1 if ethnicity=="Hispanic"
replace hisp=1 if ethnicity=="mexican"
replace hisp=1 if ethnicity=="Mexican"
replace hisp=1 if ethnicity=="Chicano"
replace hisp=1 if ethnicity=="Portuguese"
replace hisp=1 if ethnicity=="Latina"
replace hisp=1 if ethnicity=="Hispanic/Latino"
replace hisp=1 if ethnicity=="hispanic"
replace hisp=1 if ethnicity=="Mexican-American"
replace hisp=1 if ethnicity=="Latino"
replace hisp=1 if ethnicity=="Mexican American"
replace hisp=1 if ethnicity=="mexican "
label var hisp "Indicator for Hispanic participant"

gen black=0
replace black=1 if ethnicity=="African-American"
replace black=1 if ethnicity=="Black"
replace black=1 if ethnicity=="black"
replace black=1 if ethnicity=="African American"
replace black=1 if ethnicity=="Black/African-American"
label var black "Indicator for Black participant"

gen asia=0
replace asia=1 if ethnicity=="Asian"
replace asia=1 if ethnicity=="Chinese"
replace asia=1 if ethnicity=="Vietnamese"
replace asia=1 if ethnicity=="Indian"
replace asia=1 if ethnicity=="Taiwan"
replace asia=1 if ethnicity=="Pakistan-American"
replace asia=1 if ethnicity=="China"
replace asia=1 if ethnicity=="Korea"
replace asia=1 if ethnicity=="Filipino"
replace asia=1 if ethnicity=="Korean"
replace asia=1 if ethnicity=="ASIAN"
replace asia=1 if ethnicity=="indian"
label var asia "Indicator for Asian participant"

gen nat=0
replace nat=1 if ethnicity=="Native"
replace nat=1 if ethnicity=="Native American"
label var nat "Indicator for participant from one of the Native nations"

gen other_et=0
replace other_et=1 if ethnicity=="Other"
replace other_et=1 if ethnicity=="Lebanese"
replace other_et=1 if ethnicity=="Middle Eastern"
label var other_et "Indicator for participant from other ethnicity"

gen mixed=0
replace mixed=1 if ethnicity=="Bi-racial"
replace mixed=1 if ethnicity=="African American/ Caucasian "
replace mixed=1 if ethnicity=="Hispanic-Korean"
replace mixed=1 if ethnicity=="Mexican, Filipino, Guamanian"
replace mixed=1 if ethnicity=="Hawaiian, chinese, filipino"
replace mixed=1 if ethnicity=="Hispanic-White"
replace mixed=1 if ethnicity=="White/ Asian"
replace mixed=1 if ethnicity=="Asian, White"
replace mixed=1 if ethnicity=="White/Pacific Islander"
replace mixed=1 if ethnicity=="Mexican-Korean"
label var mixed "Indicator for participant with mixed ethnicity"

* Create ethnic minority variable
gen ethnic_minority=0
replace ethnic_minority=1 if white==0
label var ethnic_minority "Indicator for non-white participant"

** Create variables for ethnicity of participant with whom one is paired
gen pair_white=0
replace pair_white=1 if pairethnicity=="White"
replace pair_white=1 if pairethnicity=="white"
replace pair_white=1 if pairethnicity=="White "
replace pair_white=1 if pairethnicity=="Albanian"
replace pair_white=1 if pairethnicity=="Israeli-White"
replace pair_white=1 if pairethnicity=="Caucasian"
replace pair_white=1 if pairethnicity=="Non-hispanic"
replace pair_white=1 if pairethnicity=="Caucasian/White"
replace pair_white=1 if pairethnicity=="causasian"
replace pair_white=1 if pairethnicity=="Caucasion"
label var pair_white "Indicator for being paired with white participant"

gen pair_hisp=0
replace pair_hisp=1 if pairethnicity=="Hispanic"
replace pair_hisp=1 if pairethnicity=="mexican"
replace pair_hisp=1 if pairethnicity=="Mexican"
replace pair_hisp=1 if pairethnicity=="Chicano"
replace pair_hisp=1 if pairethnicity=="Portuguese"
replace pair_hisp=1 if pairethnicity=="Latina"
replace pair_hisp=1 if pairethnicity=="Hispanic/Latino"
replace pair_hisp=1 if pairethnicity=="hispanic"
replace pair_hisp=1 if pairethnicity=="Mexican-American"
replace pair_hisp=1 if pairethnicity=="Latino"
replace pair_hisp=1 if pairethnicity=="Mexican American"
replace pair_hisp=1 if pairethnicity=="mexican "
label var pair_hisp "Indicator for being paired with Hispanic participant"

gen pair_black=0
replace pair_black=1 if pairethnicity=="African-American"
replace pair_black=1 if pairethnicity=="Black"
replace pair_black=1 if pairethnicity=="black"
replace pair_black=1 if pairethnicity=="African American"
replace pair_black=1 if pairethnicity=="Black/African-American"
label var pair_black "Indicator for being paired with Black participant"

gen pair_asia=0
replace pair_asia=1 if pairethnicity=="Asian"
replace pair_asia=1 if pairethnicity=="Chinese"
replace pair_asia=1 if pairethnicity=="Vietnamese"
replace pair_asia=1 if pairethnicity=="Indian"
replace pair_asia=1 if pairethnicity=="Taiwan"
replace pair_asia=1 if pairethnicity=="Pakistan-American"
replace pair_asia=1 if pairethnicity=="China"
replace pair_asia=1 if pairethnicity=="Korea"
replace pair_asia=1 if pairethnicity=="Filipino"
replace pair_asia=1 if pairethnicity=="Korean"
replace pair_asia=1 if pairethnicity=="ASIAN"
replace pair_asia=1 if pairethnicity=="indian"
label var pair_asia "Indicator for being paired with Asian participant"

gen pair_nat=0
replace pair_nat =1 if pairethnicity=="Native"
replace pair_nat =1 if pairethnicity=="Native American"
label var pair_nat "Indicator for being paired with participant from one of the Native nations"

gen pair_other_et=0
replace pair_other_et =1 if pairethnicity=="Other"
replace pair_other_et =1 if pairethnicity=="Lebanese"
replace pair_other_et =1 if pairethnicity=="Middle Eastern"
label var pair_other_et "Indicator for being paired with participant from another ethnicity"

gen pair_mixed=0
replace pair_mixed=1 if pairethnicity=="Bi-racial"
replace pair_mixed=1 if pairethnicity=="African American/ Caucasian "
replace pair_mixed=1 if pairethnicity=="Hispanic-Korean"
replace pair_mixed=1 if pairethnicity=="Mexican, Filipino, Guamanian"
replace pair_mixed=1 if pairethnicity=="Hawaiian, chinese, filipino"
replace pair_mixed=1 if pairethnicity=="Hispanic-White"
replace pair_mixed=1 if pairethnicity=="White/ Asian"
replace pair_mixed=1 if pairethnicity=="Asian, White"
replace pair_mixed=1 if pairethnicity=="White/Pacific Islander"
replace pair_mixed=1 if pairethnicity=="Mexican-Korean"
label var pair_mixed "Indicator for being paired with participant with mixed ethnicity"

* Create ethnic minority variable for the participant with whom one is paired
gen pair_ethnic_minority=(1-pair_white)
label var pair_ethnic_minority "Indicator for being paired with non-white participant"

* Create different ethnicity variable for the participant with whom one is paired
gen pair_differerent_ethic_group=0
replace pair_differerent_ethic_group=1 if white==1 & pair_white!=1
replace pair_differerent_ethic_group=1 if black==1 & pair_black!=1
replace pair_differerent_ethic_group=1 if hisp==1 & pair_hisp!=1
replace pair_differerent_ethic_group=1 if asia==1 & pair_asia!=1
replace pair_differerent_ethic_group=1 if nat==1 & pair_nat!=1
label var pair_differerent_ethic_group "Indicator for being paired with participant from a different ethnicity"
* Note: this measure excludes categories mixed and other ethnicities, because 
* ethnicity sometimes vary within groups and can be similar across groups.

* Create variable for the rich who have no contact with poor and contact with poor
gen rich_nocontact=pair_high_wage if high_wage==1
gen rich_contact=(1-pair_high_wage)  if high_wage==1
label var rich_nocontact "Indicator for no identification of a low-wage participant"
label var rich_contact "Indicator for identification of a low-wage participant"

* Create variable for intra-ethnic contact (intra)
* Note: inter-ethnic contact is identified by (1-intra)
gen intra=0
replace intra=1 if white==1 & pair_white==1 | ethnic_minority==1 & ///
pair_ethnic_minority==1
label var intra "Indicator for intra-ethnic identification"

* Create variables that distinguish, for the rich, intra-ethnic and inter-ethnic
* contact with the poor
gen rich_contact_intra=(1-pair_high_wage)*intra if high_wage==1
gen rich_contact_inter=(1-pair_high_wage)*(1-intra) if high_wage==1
label var rich_contact_intra "Indicator for high-wage intra-ethnic identification of a low-wage participant"
label var rich_contact_inter "Indicator for high-wage inter-ethnic identification of a low-wage participant"

* Has one identifiable friend in the session (information available for session 13-24 only)
gen friend_in_session=0
replace friend_in_session=1 if id==127
replace friend_in_session=1 if id==128
replace friend_in_session=1 if id==142
replace friend_in_session=1 if id==145
replace friend_in_session=1 if id==147
replace friend_in_session=1 if id==148
replace friend_in_session=1 if id==156
replace friend_in_session=1 if id==158
replace friend_in_session=1 if id==171
replace friend_in_session=1 if id==173
replace friend_in_session=1 if id==181
replace friend_in_session=1 if id==182
replace friend_in_session=1 if id==185
replace friend_in_session=1 if id==186
replace friend_in_session=1 if id==190
replace friend_in_session=1 if id==201
replace friend_in_session=1 if id==207
replace friend_in_session=1 if id==208
replace friend_in_session=1 if id==210
replace friend_in_session=1 if id==211
replace friend_in_session=1 if id==213
replace friend_in_session=1 if id==221
replace friend_in_session=1 if id==223
replace friend_in_session=1 if id==224
replace friend_in_session=1 if id==225
replace friend_in_session=1 if id==226
replace friend_in_session=1 if id==228
replace friend_in_session=1 if id==231
replace friend_in_session=1 if id==236
label var friend_in_session "Indicator for participant reporting having at least 1 friend in session (1 source)"

replace interact_friend=0 if interact_friend==.
label var friend_in_session "Indicator for participant reporting being paired with friend (1 source)"
gen friend=0
replace friend=1 if friend_in_session>1 & friend_in_session!=.
replace friend=1 if friend_in_session==1 & friend_in_session!=.
replace friend=1 if nb_friends_in_session>=1 & nb_friends_in_session!=.
br if interact_friend==1
replace friend=1 if id==27 | id==29 | id==33 | ///
id==36 | id==44 | id==83 | id==85 | id==109 | ///
id==110 | id==115 | id==116 | id==119 | id==139 | ///
id==186 | id==205 | id==206
label var friend "Indicator for participant reporting having at least 1 friend in session (from 2 sources)"

* High-wage participants who are paired at least once with a friend during a round
gen high_id_interacted_friend=0
replace high_id_interacted_friend=1 if id==29 | ///
id==33 | ///
id==83 | ///
id==110 | ///
id==116 | ///
id==186 | ///
id==206
label var high_id_interacted_friend "Indicator for high-wage participant paired with friend"








******************************* 
******* Data Preparation ****** 
** Inter-ethnic Interactions ** 
******************************* 


* Create ethnicity variables for each rank
* Rank 1, takes 1 for white and 0 for minority
gen r1=.
label var r1 "Indicator for choosing white participant in first rank"

replace r1 =1 if erank1=="White"
replace r1 =1 if erank1=="white"
replace r1 =1 if erank1=="White "
replace r1 =1 if erank1=="Albanian"
replace r1 =1 if erank1=="Israeli-White"
replace r1 =1 if erank1=="Caucasian"
replace r1 =1 if erank1=="Non-hispanic"
replace r1 =1 if erank1=="Caucasian/White"
replace r1 =1 if erank1=="causasian"
replace r1 =1 if erank1=="Caucasion"

replace r1 =0 if erank1=="Hispanic"
replace r1 =0 if erank1=="mexican"
replace r1 =0 if erank1=="Mexican"
replace r1 =0 if erank1=="Chicano"
replace r1 =0 if erank1=="Portuguese"
replace r1 =0 if erank1=="Latina"
replace r1 =0 if erank1=="Hispanic/Latino"
replace r1 =0 if erank1=="hispanic"
replace r1 =0 if erank1=="Mexican-American"
replace r1 =0 if erank1=="Latino"
replace r1 =0 if erank1=="Mexican American"
replace r1 =0 if erank1=="mexican "

replace r1 =0 if erank1=="African-American"
replace r1 =0 if erank1=="Black"
replace r1 =0 if erank1=="black"
replace r1 =0 if erank1=="African American"
replace r1 =0 if erank1=="Black/African-American"

replace r1 =0 if erank1=="Asian"
replace r1 =0 if erank1=="Chinese"
replace r1 =0 if erank1=="Vietnamese"
replace r1 =0 if erank1=="Indian"
replace r1 =0 if erank1=="Taiwan"
replace r1 =0 if erank1=="Pakistan-American"
replace r1 =0 if erank1=="China"
replace r1 =0 if erank1=="Korea"
replace r1 =0 if erank1=="Filipino"
replace r1 =0 if erank1=="Korean"
replace r1 =0 if erank1=="ASIAN"
replace r1 =0 if erank1=="indian"

replace r1 =0 if erank1=="Native"
replace r1 =0 if erank1=="Native American"

replace r1 =0 if erank1=="Other"
replace r1 =0 if erank1=="Lebanese"
replace r1 =0 if erank1=="Middle Eastern"

replace r1 =0 if erank1=="Bi-racial"
replace r1 =0 if erank1=="African American/ Caucasian "
replace r1 =0 if erank1=="Hispanic-Korean"
replace r1 =0 if erank1=="Mexican, Filipino, Guamanian"
replace r1 =0 if erank1=="Hawaiian, chinese, filipino"
replace r1 =0 if erank1=="Hispanic-White"
replace r1 =0 if erank1=="White/ Asian"
replace r1 =0 if erank1=="Asian, White"
replace r1 =0 if erank1=="White/Pacific Islander"
replace r1 =0 if erank1=="Mexican-Korean"

* rank 2
gen r2=.
label var r2 "Indicator for choosing white participant in second rank"

replace r2 =1 if erank2=="White"
replace r2 =1 if erank2=="white"
replace r2 =1 if erank2=="White "
replace r2 =1 if erank2=="Albanian"
replace r2 =1 if erank2=="Israeli-White"
replace r2 =1 if erank2=="Caucasian"
replace r2 =1 if erank2=="Non-hispanic"
replace r2 =1 if erank2=="Caucasian/White"
replace r2 =1 if erank2=="causasian"
replace r2 =1 if erank2=="Caucasion"

replace r2 =0 if erank2=="Hispanic"
replace r2 =0 if erank2=="mexican"
replace r2 =0 if erank2=="Mexican"
replace r2 =0 if erank2=="Chicano"
replace r2 =0 if erank2=="Portuguese"
replace r2 =0 if erank2=="Latina"
replace r2 =0 if erank2=="Hispanic/Latino"
replace r2 =0 if erank2=="hispanic"
replace r2 =0 if erank2=="Mexican-American"
replace r2 =0 if erank2=="Latino"
replace r2 =0 if erank2=="Mexican American"
replace r2 =0 if erank2=="mexican "

replace r2 =0 if erank2=="African-American"
replace r2 =0 if erank2=="Black"
replace r2 =0 if erank2=="black"
replace r2 =0 if erank2=="African American"
replace r2 =0 if erank2=="Black/African-American"

replace r2 =0 if erank2=="Asian"
replace r2 =0 if erank2=="Chinese"
replace r2 =0 if erank2=="Vietnamese"
replace r2 =0 if erank2=="Indian"
replace r2 =0 if erank2=="Taiwan"
replace r2 =0 if erank2=="Pakistan-American"
replace r2 =0 if erank2=="China"
replace r2 =0 if erank2=="Korea"
replace r2 =0 if erank2=="Filipino"
replace r2 =0 if erank2=="Korean"
replace r2 =0 if erank2=="ASIAN"
replace r2 =0 if erank2=="indian"

replace r2 =0 if erank2=="Native"
replace r2 =0 if erank2=="Native American"

replace r2 =0 if erank2=="Other"
replace r2 =0 if erank2=="Lebanese"
replace r2 =0 if erank2=="Middle Eastern"

replace r2 =0 if erank2=="Bi-racial"
replace r2 =0 if erank2=="African American/ Caucasian "
replace r2 =0 if erank2=="Hispanic-Korean"
replace r2 =0 if erank2=="Mexican, Filipino, Guamanian"
replace r2 =0 if erank2=="Hawaiian, chinese, filipino"
replace r2 =0 if erank2=="Hispanic-White"
replace r2 =0 if erank2=="White/ Asian"
replace r2 =0 if erank2=="Asian, White"
replace r2 =0 if erank2=="White/Pacific Islander"
replace r2 =0 if erank2=="Mexican-Korean"


* rank 3
gen r3 =.
label var r3 "Indicator for choosing white participant in third rank"

replace r3 =1 if erank3=="White"
replace r3 =1 if erank3=="white"
replace r3 =1 if erank3=="White "
replace r3 =1 if erank3=="Albanian"
replace r3 =1 if erank3=="Israeli-White"
replace r3 =1 if erank3=="Caucasian"
replace r3 =1 if erank3=="Non-hispanic"
replace r3 =1 if erank3=="Caucasian/White"
replace r3 =1 if erank3=="causasian"
replace r3 =1 if erank3=="Caucasion"

replace r3 =0 if erank3=="Hispanic"
replace r3 =0 if erank3=="mexican"
replace r3 =0 if erank3=="Mexican"
replace r3 =0 if erank3=="Chicano"
replace r3 =0 if erank3=="Portuguese"
replace r3 =0 if erank3=="Latina"
replace r3 =0 if erank3=="Hispanic/Latino"
replace r3 =0 if erank3=="hispanic"
replace r3 =0 if erank3=="Mexican-American"
replace r3 =0 if erank3=="Latino"
replace r3 =0 if erank3=="Mexican American"
replace r3 =0 if erank3=="mexican "

replace r3 =0 if erank3=="African-American"
replace r3 =0 if erank3=="Black"
replace r3 =0 if erank3=="black"
replace r3 =0 if erank3=="African American"
replace r3 =0 if erank3=="Black/African-American"

replace r3 =0 if erank3=="Asian"
replace r3 =0 if erank3=="Chinese"
replace r3 =0 if erank3=="Vietnamese"
replace r3 =0 if erank3=="Indian"
replace r3 =0 if erank3=="Taiwan"
replace r3 =0 if erank3=="Pakistan-American"
replace r3 =0 if erank3=="China"
replace r3 =0 if erank3=="Korea"
replace r3 =0 if erank3=="Filipino"
replace r3 =0 if erank3=="Korean"
replace r3 =0 if erank3=="ASIAN"
replace r3 =0 if erank3=="indian"

replace r3 =0 if erank3=="Native"
replace r3 =0 if erank3=="Native American"

replace r3 =0 if erank3=="Other"
replace r3 =0 if erank3=="Lebanese"
replace r3 =0 if erank3=="Middle Eastern"

replace r3 =0 if erank3=="Bi-racial"
replace r3 =0 if erank3=="African American/ Caucasian "
replace r3 =0 if erank3=="Hispanic-Korean"
replace r3 =0 if erank3=="Mexican, Filipino, Guamanian"
replace r3 =0 if erank3=="Hawaiian, chinese, filipino"
replace r3 =0 if erank3=="Hispanic-White"
replace r3 =0 if erank3=="White/ Asian"
replace r3 =0 if erank3=="Asian, White"
replace r3 =0 if erank3=="White/Pacific Islander"
replace r3 =0 if erank3=="Mexican-Korean"

* rank 4
gen r4=.
label var r4 "Indicator for choosing white participant in fourth rank"

replace r4 =1 if erank4=="White"
replace r4 =1 if erank4=="white"
replace r4 =1 if erank4=="White "
replace r4 =1 if erank4=="Albanian"
replace r4 =1 if erank4=="Israeli-White"
replace r4 =1 if erank4=="Caucasian"
replace r4 =1 if erank4=="Non-hispanic"
replace r4 =1 if erank4=="Caucasian/White"
replace r4 =1 if erank4=="causasian"
replace r4 =1 if erank4=="Caucasion"

replace r4 =0 if erank4=="Hispanic"
replace r4 =0 if erank4=="mexican"
replace r4 =0 if erank4=="Mexican"
replace r4 =0 if erank4=="Chicano"
replace r4 =0 if erank4=="Portuguese"
replace r4 =0 if erank4=="Latina"
replace r4 =0 if erank4=="Hispanic/Latino"
replace r4 =0 if erank4=="hispanic"
replace r4 =0 if erank4=="Mexican-American"
replace r4 =0 if erank4=="Latino"
replace r4 =0 if erank4=="Mexican American"
replace r4 =0 if erank4=="mexican "

replace r4 =0 if erank4=="African-American"
replace r4 =0 if erank4=="Black"
replace r4 =0 if erank4=="black"
replace r4 =0 if erank4=="African American"
replace r4 =0 if erank4=="Black/African-American"

replace r4 =0 if erank4=="Asian"
replace r4 =0 if erank4=="Chinese"
replace r4 =0 if erank4=="Vietnamese"
replace r4 =0 if erank4=="Indian"
replace r4 =0 if erank4=="Taiwan"
replace r4 =0 if erank4=="Pakistan-American"
replace r4 =0 if erank4=="China"
replace r4 =0 if erank4=="Korea"
replace r4 =0 if erank4=="Filipino"
replace r4 =0 if erank4=="Korean"
replace r4 =0 if erank4=="ASIAN"
replace r4 =0 if erank4=="indian"

replace r4 =0 if erank4=="Native"
replace r4 =0 if erank4=="Native American"

replace r4 =0 if erank4=="Other"
replace r4 =0 if erank4=="Lebanese"
replace r4 =0 if erank4=="Middle Eastern"

replace r4 =0 if erank4=="Bi-racial"
replace r4 =0 if erank4=="African American/ Caucasian "
replace r4 =0 if erank4=="Hispanic-Korean"
replace r4 =0 if erank4=="Mexican, Filipino, Guamanian"
replace r4 =0 if erank4=="Hawaiian, chinese, filipino"
replace r4 =0 if erank4=="Hispanic-White"
replace r4 =0 if erank4=="White/ Asian"
replace r4 =0 if erank4=="Asian, White"
replace r4 =0 if erank4=="White/Pacific Islander"
replace r4 =0 if erank4=="Mexican-Korean"

* rank 5
gen r5=.
label var r5 "Indicator for choosing white participant in fifth rank"

replace r5 =1 if erank5=="White"
replace r5 =1 if erank5=="white"
replace r5 =1 if erank5=="White "
replace r5 =1 if erank5=="Albanian"
replace r5 =1 if erank5=="Israeli-White"
replace r5 =1 if erank5=="Caucasian"
replace r5 =1 if erank5=="Non-hispanic"
replace r5 =1 if erank5=="Caucasian/White"
replace r5 =1 if erank5=="causasian"
replace r5 =1 if erank5=="Caucasion"

replace r5 =0 if erank5=="Hispanic"
replace r5 =0 if erank5=="mexican"
replace r5 =0 if erank5=="Mexican"
replace r5 =0 if erank5=="Chicano"
replace r5 =0 if erank5=="Portuguese"
replace r5 =0 if erank5=="Latina"
replace r5 =0 if erank5=="Hispanic/Latino"
replace r5 =0 if erank5=="hispanic"
replace r5 =0 if erank5=="Mexican-American"
replace r5 =0 if erank5=="Latino"
replace r5 =0 if erank5=="Mexican American"
replace r5 =0 if erank5=="mexican "

replace r5 =0 if erank5=="African-American"
replace r5 =0 if erank5=="Black"
replace r5 =0 if erank5=="black"
replace r5 =0 if erank5=="African American"
replace r5 =0 if erank5=="Black/African-American"

replace r5 =0 if erank5=="Asian"
replace r5 =0 if erank5=="Chinese"
replace r5 =0 if erank5=="Vietnamese"
replace r5 =0 if erank5=="Indian"
replace r5 =0 if erank5=="Taiwan"
replace r5 =0 if erank5=="Pakistan-American"
replace r5 =0 if erank5=="China"
replace r5 =0 if erank5=="Korea"
replace r5 =0 if erank5=="Filipino"
replace r5 =0 if erank5=="Korean"
replace r5 =0 if erank5=="ASIAN"
replace r5 =0 if erank5=="indian"

replace r5 =0 if erank5=="Native"
replace r5 =0 if erank5=="Native American"

replace r5 =0 if erank5=="Other"
replace r5 =0 if erank5=="Lebanese"
replace r5 =0 if erank5=="Middle Eastern"

replace r5 =0 if erank5=="Bi-racial"
replace r5 =0 if erank5=="African American/ Caucasian "
replace r5 =0 if erank5=="Hispanic-Korean"
replace r5 =0 if erank5=="Mexican, Filipino, Guamanian"
replace r5 =0 if erank5=="Hawaiian, chinese, filipino"
replace r5 =0 if erank5=="Hispanic-White"
replace r5 =0 if erank5=="White/ Asian"
replace r5 =0 if erank5=="Asian, White"
replace r5 =0 if erank5=="White/Pacific Islander"
replace r5 =0 if erank5=="Mexican-Korean"

* rank 6
gen r6=.
label var r6 "Indicator for choosing white participant in sixth rank"

replace r6 =1 if erank6=="White"
replace r6 =1 if erank6=="white"
replace r6 =1 if erank6=="White "
replace r6 =1 if erank6=="Albanian"
replace r6 =1 if erank6=="Israeli-White"
replace r6 =1 if erank6=="Caucasian"
replace r6 =1 if erank6=="Non-hispanic"
replace r6 =1 if erank6=="Caucasian/White"
replace r6 =1 if erank6=="causasian"
replace r6 =1 if erank6=="Caucasion"

replace r6 =0 if erank6=="Hispanic"
replace r6 =0 if erank6=="mexican"
replace r6 =0 if erank6=="Mexican"
replace r6 =0 if erank6=="Chicano"
replace r6 =0 if erank6=="Portuguese"
replace r6 =0 if erank6=="Latina"
replace r6 =0 if erank6=="Hispanic/Latino"
replace r6 =0 if erank6=="hispanic"
replace r6 =0 if erank6=="Mexican-American"
replace r6 =0 if erank6=="Latino"
replace r6 =0 if erank6=="Mexican American"
replace r6 =0 if erank6=="mexican "

replace r6 =0 if erank6=="African-American"
replace r6 =0 if erank6=="Black"
replace r6 =0 if erank6=="black"
replace r6 =0 if erank6=="African American"
replace r6 =0 if erank6=="Black/African-American"

replace r6 =0 if erank6=="Asian"
replace r6 =0 if erank6=="Chinese"
replace r6 =0 if erank6=="Vietnamese"
replace r6 =0 if erank6=="Indian"
replace r6 =0 if erank6=="Taiwan"
replace r6 =0 if erank6=="Pakistan-American"
replace r6 =0 if erank6=="China"
replace r6 =0 if erank6=="Korea"
replace r6 =0 if erank6=="Filipino"
replace r6 =0 if erank6=="Korean"
replace r6 =0 if erank6=="ASIAN"
replace r6 =0 if erank6=="indian"

replace r6 =0 if erank6=="Native"
replace r6 =0 if erank6=="Native American"

replace r6 =0 if erank6=="Other"
replace r6 =0 if erank6=="Lebanese"
replace r6 =0 if erank6=="Middle Eastern"

replace r6 =0 if erank6=="Bi-racial"
replace r6 =0 if erank6=="African American/ Caucasian "
replace r6 =0 if erank6=="Hispanic-Korean"
replace r6 =0 if erank6=="Mexican, Filipino, Guamanian"
replace r6 =0 if erank6=="Hawaiian, chinese, filipino"
replace r6 =0 if erank6=="Hispanic-White"
replace r6 =0 if erank6=="White/ Asian"
replace r6 =0 if erank6=="Asian, White"
replace r6 =0 if erank6=="White/Pacific Islander"
replace r6 =0 if erank6=="Mexican-Korean"

* rank 7
gen r7=.
label var r7 "Indicator for choosing white participant in seventh rank"

replace r7 =1 if erank7=="White"
replace r7 =1 if erank7=="white"
replace r7 =1 if erank7=="White "
replace r7 =1 if erank7=="Albanian"
replace r7 =1 if erank7=="Israeli-White"
replace r7 =1 if erank7=="Caucasian"
replace r7 =1 if erank7=="Non-hispanic"
replace r7 =1 if erank7=="Caucasian/White"
replace r7 =1 if erank7=="causasian"
replace r7 =1 if erank7=="Caucasion"

replace r7 =0 if erank7=="Hispanic"
replace r7 =0 if erank7=="mexican"
replace r7 =0 if erank7=="Mexican"
replace r7 =0 if erank7=="Chicano"
replace r7 =0 if erank7=="Portuguese"
replace r7 =0 if erank7=="Latina"
replace r7 =0 if erank7=="Hispanic/Latino"
replace r7 =0 if erank7=="hispanic"
replace r7 =0 if erank7=="Mexican-American"
replace r7 =0 if erank7=="Latino"
replace r7 =0 if erank7=="Mexican American"
replace r7 =0 if erank7=="mexican "

replace r7 =0 if erank7=="African-American"
replace r7 =0 if erank7=="Black"
replace r7 =0 if erank7=="black"
replace r7 =0 if erank7=="African American"
replace r7 =0 if erank7=="Black/African-American"

replace r7 =0 if erank7=="Asian"
replace r7 =0 if erank7=="Chinese"
replace r7 =0 if erank7=="Vietnamese"
replace r7 =0 if erank7=="Indian"
replace r7 =0 if erank7=="Taiwan"
replace r7 =0 if erank7=="Pakistan-American"
replace r7 =0 if erank7=="China"
replace r7 =0 if erank7=="Korea"
replace r7 =0 if erank7=="Filipino"
replace r7 =0 if erank7=="Korean"
replace r7 =0 if erank7=="ASIAN"
replace r7 =0 if erank7=="indian"

replace r7 =0 if erank7 =="Native"
replace r7 =0 if erank7=="Native American"

replace r7 =0 if erank7=="Other"
replace r7 =0 if erank7=="Lebanese"
replace r7 =0 if erank7=="Middle Eastern"

replace r7 =0 if erank7=="Bi-racial"
replace r7 =0 if erank7=="African American/ Caucasian "
replace r7 =0 if erank7=="Hispanic-Korean"
replace r7 =0 if erank7=="Mexican, Filipino, Guamanian"
replace r7 =0 if erank7=="Hawaiian, chinese, filipino"
replace r7 =0 if erank7=="Hispanic-White"
replace r7 =0 if erank7=="White/ Asian"
replace r7 =0 if erank7=="Asian, White"
replace r7 =0 if erank7=="White/Pacific Islander"
replace r7 =0 if erank7=="Mexican-Korean"

* rank 8
gen r8=.
label var r8 "Indicator for choosing white participant in eigth rank"

replace r8 =1 if erank8=="White"
replace r8 =1 if erank8=="white"
replace r8 =1 if erank8=="White "
replace r8 =1 if erank8=="Albanian"
replace r8 =1 if erank8=="Israeli-White"
replace r8 =1 if erank8=="Caucasian"
replace r8 =1 if erank8=="Non-hispanic"
replace r8 =1 if erank8=="Caucasian/White"
replace r8 =1 if erank8=="causasian"
replace r8 =1 if erank8=="Caucasion"

replace r8 =0 if erank8=="Hispanic"
replace r8 =0 if erank8=="mexican"
replace r8 =0 if erank8=="Mexican"
replace r8 =0 if erank8=="Chicano"
replace r8 =0 if erank8=="Portuguese"
replace r8 =0 if erank8=="Latina"
replace r8 =0 if erank8=="Hispanic/Latino"
replace r8 =0 if erank8=="hispanic"
replace r8 =0 if erank8=="Mexican-American"
replace r8 =0 if erank8=="Latino"
replace r8 =0 if erank8=="Mexican American"
replace r8 =0 if erank8=="mexican "

replace r8 =0 if erank8=="African-American"
replace r8 =0 if erank8=="Black"
replace r8 =0 if erank8=="black"
replace r8 =0 if erank8=="African American"
replace r8 =0 if erank8=="Black/African-American"

replace r8 =0 if erank8=="Asian"
replace r8 =0 if erank8=="Chinese"
replace r8 =0 if erank8=="Vietnamese"
replace r8 =0 if erank8=="Indian"
replace r8 =0 if erank8=="Taiwan"
replace r8 =0 if erank8=="Pakistan-American"
replace r8 =0 if erank8=="China"
replace r8 =0 if erank8=="Korea"
replace r8 =0 if erank8=="Filipino"
replace r8 =0 if erank8=="Korean"
replace r8 =0 if erank8=="ASIAN"
replace r8 =0 if erank8=="indian"

replace r8 =0 if erank8=="Native"
replace r8 =0 if erank8=="Native American"

replace r8 =0 if erank8=="Other"
replace r8 =0 if erank8=="Lebanese"
replace r8 =0 if erank8=="Middle Eastern"

replace r8 =0 if erank8=="Bi-racial"
replace r8 =0 if erank8=="African American/ Caucasian "
replace r8 =0 if erank8=="Hispanic-Korean"
replace r8 =0 if erank8=="Mexican, Filipino, Guamanian"
replace r8 =0 if erank8=="Hawaiian, chinese, filipino"
replace r8 =0 if erank8=="Hispanic-White"
replace r8 =0 if erank8=="White/ Asian"
replace r8 =0 if erank8=="Asian, White"
replace r8 =0 if erank8=="White/Pacific Islander"
replace r8 =0 if erank8=="Mexican-Korean"

* rank 9
gen r9=.
label var r9 "Indicator for choosing white participant in ninth rank"

replace r9 =1 if erank9=="White"
replace r9 =1 if erank9=="white"
replace r9 =1 if erank9=="White "
replace r9 =1 if erank9=="Albanian"
replace r9 =1 if erank9=="Israeli-White"
replace r9 =1 if erank9=="Caucasian"
replace r9 =1 if erank9=="Non-hispanic"
replace r9 =1 if erank9=="Caucasian/White"
replace r9 =1 if erank9=="causasian"
replace r9 =1 if erank9=="Caucasion"

replace r9 =0 if erank9 =="Hispanic"
replace r9 =0 if erank9=="mexican"
replace r9 =0 if erank9=="Mexican"
replace r9 =0 if erank9=="Chicano"
replace r9 =0 if erank9=="Portuguese"
replace r9 =0 if erank9=="Latina"
replace r9 =0 if erank9=="Hispanic/Latino"
replace r9 =0 if erank9=="hispanic"
replace r9 =0 if erank9=="Mexican-American"
replace r9 =0 if erank9=="Latino"
replace r9 =0 if erank9=="Mexican American"
replace r9 =0 if erank9=="mexican "

replace r9 =0 if erank9=="African-American"
replace r9 =0 if erank9=="Black"
replace r9 =0 if erank9=="black"
replace r9 =0 if erank9=="African American"
replace r9 =0 if erank9=="Black/African-American"

replace r9 =0 if erank9=="Asian"
replace r9 =0 if erank9=="Chinese"
replace r9 =0 if erank9=="Vietnamese"
replace r9 =0 if erank9=="Indian"
replace r9 =0 if erank9=="Taiwan"
replace r9 =0 if erank9=="Pakistan-American"
replace r9 =0 if erank9=="China"
replace r9 =0 if erank9=="Korea"
replace r9 =0 if erank9=="Filipino"
replace r9 =0 if erank9=="Korean"
replace r9 =0 if erank9=="ASIAN"
replace r9 =0 if erank9=="indian"

replace r9 =0 if erank9=="Native"
replace r9 =0 if erank9=="Native American"

replace r9 =0 if erank9=="Other"
replace r9 =0 if erank9=="Lebanese"
replace r9 =0 if erank9=="Middle Eastern"

replace r9 =0 if erank9=="Bi-racial"
replace r9 =0 if erank9=="African American/ Caucasian "
replace r9 =0 if erank9=="Hispanic-Korean"
replace r9 =0 if erank9=="Mexican, Filipino, Guamanian"
replace r9 =0 if erank9=="Hawaiian, chinese, filipino"
replace r9 =0 if erank9=="Hispanic-White"
replace r9 =0 if erank9=="White/ Asian"
replace r9 =0 if erank9=="Asian, White"
replace r9 =0 if erank9=="White/Pacific Islander"
replace r9 =0 if erank9=="Mexican-Korean"

* Create number of whites chosen in first four ranks
gen f4rank=r1 + r2 + r3 + r4
label var f4rank "Number of whites chosen in first four ranks"
* Create number of whites chosen in last four ranks
gen l4rank=r6 + r7 + r8 + r9
label var l4rank "Number of ethnic minorities chosen in last four ranks"
* Create dif variables
gen dif_4rank=f4rank-l4rank
label var dif_4rank "Number of whites chosen in first four minus last four ranks"


* Proportion of whites vs. minorities in each session
egen prop_whites_session=mean(white), by(session)
egen prop_men_session=mean(man), by(session)
label var prop_whites_session "Proportion of whites in session"
label var prop_men_session "Proportion of men in session"

* Correction
gen int_rank1=rank1
replace int_rank1="." if rank1=="Indifferent"
gen int_rank2=rank2
replace int_rank2="." if rank2=="Indifferent"
gen int_rank3=rank3
replace int_rank3="." if rank3=="Indifferent"

gen int_rank4=rank4
replace int_rank4="." if rank4=="Indifferent"
gen int_rank5=rank5
replace int_rank5="." if rank5=="Indifferent"
gen int_rank6=rank6
replace int_rank6="." if rank6=="Indifferent"

gen int_rank7=rank7
replace int_rank7="." if rank7=="Indifferent"
gen int_rank8=rank8
replace int_rank8="." if rank8=="Indifferent"
gen int_rank9=rank9
replace int_rank9="." if rank9=="Indifferent"

destring int_rank1 int_rank2 int_rank3 int_rank4 int_rank5 int_rank6 ///
int_rank7 int_rank8 int_rank9, replace

* Men in selection ranks
sort session round id
gen grank1=man[_n+int_rank1-id]
gen grank2=man[_n+int_rank2-id]
gen grank3=man[_n+int_rank3-id]
gen grank4=man[_n+int_rank4-id]
gen grank5=man[_n+int_rank5-id]
gen grank6=man[_n+int_rank6-id]
gen grank7=man[_n+int_rank7-id]
gen grank8=man[_n+int_rank8-id]
gen grank9=man[_n+int_rank9-id]
label var grank1 "Choose man in rank 1 for interactions"
label var grank2 "Choose man in rank 2 for interactions"
label var grank3 "Choose man in rank 3 for interactions"
label var grank4 "Choose man in rank 4 for interactions"
label var grank5 "Choose man in rank 5 for interactions"
label var grank6 "Choose man in rank 6 for interactions"
label var grank7 "Choose man in rank 7 for interactions"
label var grank8 "Choose man in rank 8 for interactions"
label var grank9 "Choose man in rank 9 for interactions"


** Create variable for difference the number of men in first vs. last
* four ranks
gen f4grank=grank1 + grank2 + grank3 +grank4
gen l4grank=grank6 + grank7 + grank8 +grank9
gen dif_g4rank=f4grank-l4grank
label var dif_g4rank "Number of men chosen in first four minus last four ranks"
* Choosing from the other gender
gen dif_otherg4rank=dif_g4rank if man==1
replace dif_otherg4rank=-dif_g4rank if man==0
* Interaction term with gender
gen int_man_dif_g4rank=man*dif_g4rank

** Create two own session ID number variables: low (1-5) and high (6-10)
gen high_id=0
replace high_id=1 if subject>=6
label var high_id "Session ID is high (6--10) instead of low (1--5)"

* Create sum of number chosen in first four ranks
gen sum_f4rank=int_rank1 + int_rank2 + int_rank3 + int_rank4
* Create sum of number chosen in last four ranks
gen sum_l4rank=int_rank6 + int_rank7 + int_rank8 + int_rank9
* Create dif variables
gen dif_sum4rank=sum_f4rank-sum_l4rank
label var dif_sum4rank "Number of high session ID chosen in first four minus last four ranks"

* Tag participants who write their own ID number (variable: subject)
* in one of the nine ranks
gen own_id_in_ranks=0
replace own_id_in_rank=1 if subject==int_rank1
replace own_id_in_rank=1 if subject==int_rank2
replace own_id_in_rank=1 if subject==int_rank3
replace own_id_in_rank=1 if subject==int_rank4
replace own_id_in_rank=1 if subject==int_rank5
replace own_id_in_rank=1 if subject==int_rank6
replace own_id_in_rank=1 if subject==int_rank7
replace own_id_in_rank=1 if subject==int_rank8
replace own_id_in_rank=1 if subject==int_rank9
label var own_id_in_ranks "Participant chose own session ID in a rank"

gen double_id_in_ranks=0
replace double_id_in_ranks=1 if int_rank1==int_rank2
replace double_id_in_ranks=1 if int_rank1==int_rank3
replace double_id_in_ranks=1 if int_rank1==int_rank4
replace double_id_in_ranks=1 if int_rank1==int_rank5
replace double_id_in_ranks=1 if int_rank1==int_rank6
replace double_id_in_ranks=1 if int_rank1==int_rank7
replace double_id_in_ranks=1 if int_rank1==int_rank8
replace double_id_in_ranks=1 if int_rank1==int_rank9

replace double_id_in_ranks=1 if int_rank2==int_rank3
replace double_id_in_ranks=1 if int_rank2==int_rank4
replace double_id_in_ranks=1 if int_rank2==int_rank5
replace double_id_in_ranks=1 if int_rank2==int_rank6
replace double_id_in_ranks=1 if int_rank2==int_rank7
replace double_id_in_ranks=1 if int_rank2==int_rank8
replace double_id_in_ranks=1 if int_rank2==int_rank9

replace double_id_in_ranks=1 if int_rank3==int_rank4
replace double_id_in_ranks=1 if int_rank3==int_rank5
replace double_id_in_ranks=1 if int_rank3==int_rank6
replace double_id_in_ranks=1 if int_rank3==int_rank7
replace double_id_in_ranks=1 if int_rank3==int_rank8
replace double_id_in_ranks=1 if int_rank3==int_rank9

replace double_id_in_ranks=1 if int_rank4==int_rank5
replace double_id_in_ranks=1 if int_rank4==int_rank6
replace double_id_in_ranks=1 if int_rank4==int_rank7
replace double_id_in_ranks=1 if int_rank4==int_rank8
replace double_id_in_ranks=1 if int_rank4==int_rank9

replace double_id_in_ranks=1 if int_rank5==int_rank6
replace double_id_in_ranks=1 if int_rank5==int_rank7
replace double_id_in_ranks=1 if int_rank5==int_rank8
replace double_id_in_ranks=1 if int_rank5==int_rank9

replace double_id_in_ranks=1 if int_rank6==int_rank7
replace double_id_in_ranks=1 if int_rank6==int_rank8
replace double_id_in_ranks=1 if int_rank6==int_rank9

replace double_id_in_ranks=1 if int_rank7==int_rank8
replace double_id_in_ranks=1 if int_rank7==int_rank9

replace double_id_in_ranks=1 if int_rank8==int_rank9
label var double_id_in_ranks "Participant chose twice the same session ID in ranks"

* Create lasting measure (for three rounds)
sort id round
gen allrounds_dif_4rank=dif_4rank if round==0
replace allrounds_dif_4rank=dif_4rank[_n-1] if round==1
replace allrounds_dif_4rank=dif_4rank[_n-2] if round==2
label var allrounds_dif_4rank "Number of whites chosen in first four minus last four ranks, in round 1"

gen allrounds_own_id_in_ranks=own_id_in_ranks if round==0
replace allrounds_own_id_in_ranks=own_id_in_ranks[_n-1] if round==1
replace allrounds_own_id_in_ranks=own_id_in_ranks[_n-2] if round==2
label var allrounds_own_id_in_ranks "Participant chose own session ID in a rank, in round 1"

gen allrounds_double_id_in_ranks=double_id_in_ranks if round==0
replace allrounds_double_id_in_ranks=double_id_in_ranks[_n-1] if round==1
replace allrounds_double_id_in_ranks=double_id_in_ranks[_n-2] if round==2
label var allrounds_double_id_in_ranks "Participant chose twice the same session ID in ranks, in round 1"











******************************* 
******* Data Preparation ****** 
**** Interactions with Poor *** 
******************************* 

* change L into l, H into h, and I into i, to obtain consistent notation
replace highlowind="l" if highlowind=="L"
replace highlowind="h" if highlowind=="H"
replace highlowind="i" if highlowind=="I"
label var highlowind "Choose to interact with low-wage (l), high-wage (h), or indifferent (i)"

* create variable regarding selection of contact with the poor, indifference,
* or no contact (interaction with the rich)
gen choice_contact=0 if highlowind!="."
replace choice_contact=1 if highlowind=="l"
gen choice_indifferent=0 if highlowind!="."
replace choice_indifferent=1 if highlowind=="i"
gen choice_nocontact=0 if highlowind!="."
replace choice_nocontact=1 if highlowind=="h"
label var choice_contact "Participant chooses interaction with low-wage participant"
label var choice_indifferent "Participant is indifferent regarding interaction with low- or high-wage participant"
label var choice_nocontact "Participant chooses interaction with high-wage participant"

** Create variable from first round for other rounds
sort id round
gen choice_nocontact_firstround=0 if choice_nocontact!=.
replace choice_nocontact_firstround=1 if choice_nocontact==1 & round==0
replace choice_nocontact_firstround=1 if choice_nocontact[_n-1]==1 & round==1
replace choice_nocontact_firstround=1 if choice_nocontact[_n-2]==1 & round==2

label var choice_nocontact_firstround "Participant chooses interaction with high-wage participant, in round 1"











******************************* 
********* Section IV  ********* 
******************************* 



* Table 3 --- Mean redistribution rates by treatment
format proposal %12.2f
* Number of observations for rich (in text)
count if high_wage==1 & friend==0
* Number of rich participant (in text)
count if high_wage==1 & friend==0 & round==0
* Number of rich participant who are whites and minorities (in text)
count if high_wage==1 & white==1 & friend==0 & round==0
count if high_wage==1 & white==0 & friend==0 & round==0
* Lower-bound censoring rate (in text)
tab proposal if high_wage==1 & friend==0
* Column 1
sum proposal if rich_nocontact==1 & friend==0 ///
, format
sum proposal if rich_contact_intra==1 & friend==0 ///
, format
sum proposal if rich_contact_inter==1 & friend==0 ///
, format



** Table 4 --- test Hypotheses 1 and 2, Regression I
xtset id round
eststo clear
* Column 1 Upper Row --- RE regression
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0, vce(r)
testparm rich_contact
* Column 2 Upper Row --- Tobit RE regression
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & friend==0, ll(-10)
testparm rich_contact
* Column 1 Lower Rows --- RE regression
eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
* Column 2 Lower Rows --- Tobit RE regression
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Robustness checks (mentionned in note of Table 4)
* Cluster se at session level
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0, vce(cluster session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0, vce(cluster session)
testparm rich_contact_intra rich_contact_inter, equal

* Wild bootstrap cluster se at session level (randomly generated integer for seed)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0, fe
testparm rich_contact

eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0, fe vce(r)
testparm rich_contact

eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0, fe vce(cluster session)
testparm rich_contact
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0, fe vce(cluster session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 

* Version with fixed effects (not possible for Tobit) and individual-level
* se clusters recommended by referee
* Column 1 Upper Row --- FE regression with individual-level cluster se
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0, fe cluster(id)
testparm rich_contact
* Column 1 Lower Rows --- FE regression with individual-level cluster se
eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0, fe cluster(id)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal

* Interpretation of effect in text
* From Table 3, the rich's mean redistribution rates are 7.23301 (SD=24.00703)
* when interacting with the rich 13.84201 (SD=32.75471) when interacting with 
* the poor
sum proposal if rich_contact==1 & high_wage==1 & friend==0
sum proposal if rich_contact==0 & high_wage==1 & friend==0
* the effect is then 6.6072
di 13.84021-7.23301
* and, once standardized using the SD when interacting with the rich
di (13.84021-7.23301)/24.00703



** Table 5: Percentage of Participants Choosing to be paired with a White 
* in Each Rank, and OLS Regression Estimates for the Difference in Number of 
* Whites in First and Last Four Ranks, for Whites and Minorities
* Upper Panel, descriptive stats
* Whites
sum r1 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r2 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r3 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r4 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r5 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r6 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r7 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r8 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r9 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
* Minorities
sum r1 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r2 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r3 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r4 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r5 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r6 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r7 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r8 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
sum r9 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0

* Lower panel, regression analysis
* White participants
eststo clear
eststo: reg dif_4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
eststo: reg dif_4rank ///
dif_otherg4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0  & friend==0, vce(r)
eststo: reg dif_4rank ///
dif_sum4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
* Minority participants
eststo: reg dif_4rank ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
eststo: reg dif_4rank ///
dif_otherg4rank ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
eststo: reg dif_4rank ///
dif_sum4rank ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
* Whites: bootstrap se/ wild bootstrap se (mentioned in table footnote)
reg dif_4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0  & friend==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 
reg dif_4rank ///
dif_otherg4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0  & friend==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 
reg dif_4rank ///
dif_sum4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0  & friend==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 



** Table 6: subsample of white rich who choose to have more contact with whites
* than minorities
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & friend==0  ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Cluster se (in note of table)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, vce(cluster session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, vce(cluster session)
testparm rich_contact_intra rich_contact_inter, equal

* Wild bootstrap cluster se (in note of table)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0  ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, fe vce(cluster session)
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, fe vce(cluster session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 

* FE and individual-level clusters of se (in note of table)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, fe vce(cluster id)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_4rank>0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, fe vce(cluster id)
testparm rich_contact_intra rich_contact_inter, equal



** Table 7, Choices of Interactions with the Poor, and Tests of Equality of 
* Choices, for the Poor and the Rich
* Upper Panel, descriptive Stats
sum choice_contact choice_indifferent choice_nocontact if round==0 & high_wage==0 & friend==0
sum choice_contact choice_indifferent choice_nocontact if round==0 & high_wage==1 & friend==0
* Lower Panel, reg (Logit)
logit choice_nocontact if high_wage==0 & round==0 & friend==0 & choice_indifferent==0, vce(r)
logit choice_nocontact if high_wage==0 & round==0 & friend==0, vce(r)
logit choice_nocontact if high_wage==1 & round==0 & friend==0 & choice_indifferent==0, vce(r)
logit choice_nocontact if high_wage==1 & round==0 & friend==0, vce(r)
* wild bootstrap cluster se (mentioned in table footnote)
logit choice_nocontact if high_wage==0 & round==0 & friend==0 & choice_indifferent==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 
logit choice_nocontact if high_wage==0 & round==0 & friend==0, vce(cluster session)
boottest _cons=0, seed(899842) reps(10000) 
logit choice_nocontact if high_wage==1 & round==0 & friend==0 & choice_indifferent==0, vce(cluster session)
boottest _cons=0, seed(899842) reps(10000) 
logit choice_nocontact if high_wage==1 & round==0 & friend==0, vce(cluster session)
boottest _cons=0, seed(899842) reps(10000) 



** Table 8: subsample of rich who choose no contact with the poor
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 & choice_nocontact_firstround==1, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & friend==0 & choice_nocontact_firstround==1, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 & choice_nocontact_firstround==1, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 & choice_nocontact_firstround==1, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 & choice_nocontact_firstround==1, vce(cluster session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 & choice_nocontact_firstround==1, vce(cluster session)
testparm rich_contact_intra rich_contact_inter, equal

* Wild bootstrap cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 & choice_nocontact_firstround==1, fe vce(cluster session)
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 & choice_nocontact_firstround==1, fe vce(cluster session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 

* FE and individual-level clusters of se (in note of table)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 & choice_nocontact_firstround==1, fe vce(cluster id)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 & choice_nocontact_firstround==1, fe vce(cluster id)
testparm rich_contact_intra rich_contact_inter, equal

















******************************* 
****** Robustness checks ****** 
******************************* 


** Robustness check 1 (mentioned in footnote 23 of main text): 
* Exclude participants in 2 endogenous sessions (sessions 2 and 7)
* Endogenous sesions
tab session if selection=="yes"
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Cluster se 
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, cluster(session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, cluster(session)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal

* Wild cluster se
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, fe cluster(session)
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
 & session!=2 & session!=7, fe cluster(session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 


** Robustness check 2 (mentionned in main text): 
* Intra and inter ethnic contact with the poor accounting for several 
* minority groups
* Regression I (RE and Tobit RE)

* Create variables that distinguish, for the rich, intra-ethnic and inter-ethnic
* contact with the poor
gen rich_contact_intra_multiple=(1-pair_high_wage)*(1-pair_differerent_ethic_group) if high_wage==1
gen rich_contact_inter_multiple=(1-pair_high_wage)*pair_differerent_ethic_group if high_wage==1

* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact_intra_multiple rich_contact_inter_multiple ///
man white round if high_wage==1 & friend==0, vce(r)
test rich_contact_intra_multiple
test rich_contact_inter_multiple
testparm rich_contact_intra_multiple rich_contact_inter_multiple, equal
eststo: xttobit proposal rich_contact_intra_multiple rich_contact_inter_multiple ///
man white round if high_wage==1 & friend==0, ll(-10)
testparm rich_contact_intra_multiple rich_contact_inter_multiple, equal

* Cluster se
eststo: xtreg proposal rich_contact_intra_multiple rich_contact_inter_multiple ///
man white round if high_wage==1 & friend==0, vce(cluster session)
testparm rich_contact_intra_multiple rich_contact_inter_multiple, equal

* Wild bootstrap cluster se
eststo: xtreg proposal rich_contact_intra_multiple rich_contact_inter_multiple ///
man white round if high_wage==1 & friend==0, fe vce(cluster session)
boottest rich_contact_intra_multiple=rich_contact_inter_multiple, seed(899842) reps(10000) 













******************************* 
******* Online Material ******* 
******************************* 

** Table A1 --- Summary of Redistribution Rates Chosen by the Rich for Whites and Minorities Separately
format proposal %12.2f

* Column 1
sum proposal if rich_nocontact==1 & white==1 & friend==0 ///
, format
sum proposal if rich_contact_intra==1 & white==1 & friend==0 ///
, format
sum proposal if rich_contact_inter==1 & white==1 & friend==0 ///
, format
* Column 2
sum proposal if rich_nocontact==1 & white==0 & friend==0 ///
, format
sum proposal if rich_contact_intra==1 & white==0 & friend==0 ///
, format
sum proposal if rich_contact_inter==1 & white==0 & friend==0 ///
, format


** Table A2, including rich with a friend
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact  man white round ///
if high_wage==1, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1, vce(cluster session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1, vce(cluster session)
testparm rich_contact_intra rich_contact_inter, equal

* Wild bootstrap cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1, fe vce(cluster session)
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1, fe vce(cluster session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 


** Table A3, including only the rich who interacted with a poor friend
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact  man white round ///
if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, vce(cluster session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, vce(cluster session)
testparm rich_contact_intra rich_contact_inter, equal

* Wild bootstrap cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, fe vce(cluster session)
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 | ///
high_wage==1 & high_id_interacted_friend==1, fe vce(cluster session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 


** Table A4, including only the rich with a friend whom they did not encounter 
* in their interactions with the poor
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact  man white round ///
if high_wage==1 & high_id_interacted_friend==0, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & high_id_interacted_friend==0, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & high_id_interacted_friend==0, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & high_id_interacted_friend==0, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal

* Cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & high_id_interacted_friend==0, vce(cluster session)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & high_id_interacted_friend==0, vce(cluster session)
testparm rich_contact_intra rich_contact_inter, equal

* Wild bootstrap cluster se (mentioned in table footnote)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & high_id_interacted_friend==0, fe vce(cluster session)
boottest rich_contact=0, seed(899842) reps(10000) 

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & high_id_interacted_friend==0, fe vce(cluster session)
boottest rich_contact_intra, seed(899842) reps(10000) 
boottest rich_contact_inter, seed(899842) reps(10000) 
boottest rich_contact_intra=rich_contact_inter, seed(899842) reps(10000) 



* Table A5: Percentage of Participants Choosing to be paired with a White 
* in Each Rank, and OLS Regression Estimates for the Difference in Number of 
* Whites in First and Last Four Ranks, for Whites and Minorities ---
* Including All Participants with a Friend in the Session
* Upper Panel, descriptive stats
* Whites
sum r1 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r2 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r3 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r4 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r5 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r6 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r7 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r8 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r9 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
* Minorities
sum r1 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r2 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r3 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r4 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r5 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r6 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r7 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r8 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
sum r9 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0
* Lower panel, regression analysis
* White participants
eststo clear
eststo: reg dif_4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, vce(r)
eststo: reg dif_4rank ///
dif_otherg4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, vce(r)
eststo: reg dif_4rank ///
dif_sum4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, vce(r)
* Minority participants
eststo: reg dif_4rank ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, vce(r)
eststo: reg dif_4rank ///
dif_otherg4rank ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, vce(r)
eststo: reg dif_4rank ///
dif_sum4rank ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, vce(r)
* bootstrap se/ wild bootstrap se (not in text)
reg dif_4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 
reg dif_4rank ///
dif_otherg4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 
reg dif_4rank ///
dif_sum4rank ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 



** Table A6, Choices of Interactions with the Poor, and Tests of Equality of 
* Choices, for the Poor and the Rich --- Including All Participants with a 
* Friend in the Session
* Upper Panel, Descriptive Stats
sum choice_contact choice_indifferent choice_nocontact if round==0 & high_wage==0
sum choice_contact choice_indifferent choice_nocontact if round==0 & high_wage==1
* Lower Panel, Reg
logit choice_nocontact if high_wage==0 & round==0 & choice_indifferent==0, vce(r)
test _cons
logit choice_nocontact if high_wage==0 & round==0, vce(r)

logit choice_nocontact if high_wage==1 & round==0 & choice_indifferent==0, vce(r)
logit choice_nocontact if high_wage==1 & round==0, vce(r)
* Wild bootstrap cluster se (mentioned in table footnote)
logit choice_nocontact if high_wage==0 & round==0 & choice_indifferent==0, cluster(session)
boottest _cons=0, seed(899842) reps(10000) 
logit choice_nocontact if high_wage==0 & round==0, vce(cluster session)
boottest _cons=0, seed(899842) reps(10000) 
logit choice_nocontact if high_wage==1 & round==0 & choice_indifferent==0, vce(cluster session)
boottest _cons=0, seed(899842) reps(10000) 
logit choice_nocontact if high_wage==1 & round==0, vce(cluster session)
boottest _cons=0, seed(899842) reps(10000) 














******************************* 
******* Data Preparation ****** 
***** Referee Alternative *****
** Inter-ethnic Interactions ** 
******************************* 

* Referee alternative: create average rank of whites and average rank of minorities
gen mean_rank_whites=(1*r1+2*r2+3*r3+4*r4+5*r5+6*r6+7*r7+8*r8+9*r9)/9
gen mean_rank_min=(1*(1-r1)+2*(1-r2)+3*(1-r3)+4*(1-r4)+5*(1-r5)+6*(1-r6)+7*(1-r7)+8*(1-r8)+9*(1-r9))/9
gen dif_mean_rank_whi_min=mean_rank_whites-mean_rank_min

gen mean_rank_men=(1*grank1+2*grank2+3*grank3+4*grank4+5*grank5+6*grank6+7*grank7+8*grank8+9*grank9)/9
gen mean_rank_wom=(1*(1-grank1)+2*(1-grank2)+3*(1-grank3)+4*(1-grank4)+5*(1-grank5)+6*(1-grank6)+7*(1-grank7)+8*(1-grank8)+9*(1-grank9))/9
gen dif_mean_rank_men_wom=mean_rank_men-mean_rank_wom

quietly forvalues k=1(1)10 {
gen rank_id_`k'=.
quietly forvalues j=1(1)9 {
	replace rank_id_`k'=`j' if int_rank`j'==`k'
}
}
gen mean_rank_id_lowest=.
replace mean_rank_id_lowest=(rank_id_1+rank_id_2+rank_id_3+rank_id_4+rank_id_5)/5 if subject>=5 & subject<=10
replace mean_rank_id_lowest=(rank_id_1+rank_id_2+rank_id_3+rank_id_4)/4 if subject==5
replace mean_rank_id_lowest=(rank_id_1+rank_id_2+rank_id_3+rank_id_5)/4 if subject==4
replace mean_rank_id_lowest=(rank_id_1+rank_id_2+rank_id_4+rank_id_5)/4 if subject==3
replace mean_rank_id_lowest=(rank_id_1+rank_id_3+rank_id_4+rank_id_5)/4 if subject==2
replace mean_rank_id_lowest=(rank_id_2+rank_id_3+rank_id_4+rank_id_5)/4 if subject==1
gen mean_rank_id_highest=.
replace mean_rank_id_highest=(rank_id_6+rank_id_7+rank_id_8+rank_id_9+rank_id_10)/5 if subject>=1 & subject<=5
replace mean_rank_id_highest=(rank_id_6+rank_id_7+rank_id_8+rank_id_9)/4 if subject==10
replace mean_rank_id_highest=(rank_id_6+rank_id_7+rank_id_8+rank_id_10)/4 if subject==9
replace mean_rank_id_highest=(rank_id_6+rank_id_7+rank_id_9+rank_id_10)/4 if subject==8
replace mean_rank_id_highest=(rank_id_6+rank_id_8+rank_id_9+rank_id_10)/4 if subject==7
replace mean_rank_id_highest=(rank_id_7+rank_id_8+rank_id_9+rank_id_10)/4 if subject==6
gen dif_mean_id_high_low=mean_rank_id_highest-mean_rank_id_lowest

* Lasting measure (for three rounds)
sort id round
gen allrounds_dif_mean_rank_whi_min=dif_mean_rank_whi_min if round==0
replace allrounds_dif_mean_rank_whi_min=dif_mean_rank_whi_min[_n-1] if round==1
replace allrounds_dif_mean_rank_whi_min=dif_mean_rank_whi_min[_n-2] if round==2




**** Referee alternative for Table 5-6 (Refered to in footnote 26, but no analysis in text)
* Upper Panel, descriptive stats
* Whites
sum dif_mean_rank_whi_min if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
* Minorities
sum dif_mean_rank_whi_min if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
* Lower panel, regression analysis
ttest dif_mean_rank_whi_min==0 if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
ttest dif_mean_rank_whi_min==0 if ethnic_minority==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0
ttest dif_mean_rank_whi_min if round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, by(white)
* White participants
eststo clear
eststo: reg dif_mean_rank_whi_min ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
eststo: reg dif_mean_rank_whi_min ///
dif_mean_rank_men_wom ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0  & friend==0, vce(r)
eststo: reg dif_mean_rank_whi_min ///
dif_mean_id_high_low ///
if white==1 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
* Minority participants
eststo: reg dif_mean_rank_whi_min ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
eststo: reg dif_mean_rank_whi_min ///
dif_mean_rank_men_wom ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
eststo: reg dif_mean_rank_whi_min ///
dif_mean_id_high_low ///
if white==0 & round==0 & own_id_in_rank==0 & ///
double_id_in_ranks==0 & friend==0, vce(r)
* Regression I (RE and Tobit RE)
eststo: xtreg proposal rich_contact man white round ///
if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_mean_rank_whi_min<0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, vce(r)
testparm rich_contact
eststo: xttobit proposal rich_contact man white round ///
if high_wage==1 & friend==0  ///
& white==1 & allrounds_dif_mean_rank_whi_min<0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, ll(-10)
testparm rich_contact

eststo: xtreg proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_mean_rank_whi_min<0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, vce(r)
test rich_contact_intra
test rich_contact_inter
testparm rich_contact_intra rich_contact_inter, equal
eststo: xttobit proposal rich_contact_intra rich_contact_inter ///
man white round if high_wage==1 & friend==0 ///
& white==1 & allrounds_dif_mean_rank_whi_min<0 & ///
allrounds_own_id_in_ranks==0 & allrounds_double_id_in_ranks==0, ll(-10)
testparm rich_contact_intra rich_contact_inter, equal
